<!DOCTYPE html>
<html>
    <head>
        <script src="js/vue.js"></script>
    </head>
    <body>
        <div id="app">
            <button @click="add">增加学生</button>
            <button v-on:click="del">减少学生</button>
            <table border="1" width="50%" style="border-collapse: collapse;">
                <tr>
                    <th>序号</th>
                    <th>班级</th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>年龄</th>
                </tr>
                <tr align="center" v-for="(student,index) in students">
                    <td>{{index}}</td>
                    <td> {{student.grade}} </td>
                    <td> {{student.name}} </td>
                    <td> {{student.gender}} </td>
                    <td> {{student.age}} </td>
                </tr>
            </table>
        </div>
        <script>
            var vm = new Vue({
                el:'#app',
                data:{
                    students : [
                        {grade:'1',name:'张三',gender:'男',age:'25'},
                        {grade:'1',name:'张三',gender:'男',age:'25'}
                    ]
                },
                methods:{
                    add(){
                        var student = {grade:'1',name:'李四',gender:'女',age:'22'};
                        this.students.push(student);
                    },

                    del(){
                        this.students.pop();
                    }
                }
            });
        </script>
    </body>
</html>